#include <iostream>
#include <algorithm>
using namespace std;
const int N = 310;
struct S
{
	int chinese;
	int math;
	int english;
	int total;
	void S1()
	{
		total = math + chinese + english;
		
	}
	int id;
}arr[N];

bool cmp(struct S&s1,struct S& s2)
{
	if(s1.total != s2.total)
	return s1.total > s2.total;
	else if(s1.chinese != s2.chinese)
	return s1.chinese > s2.chinese;
	else 
	return s1.id < s2.id;
	
}

int main()
{
	int n = 0;
	cin >> n;
	for(int i = 0; i < n;i++ )
	{
		
		cin >> arr[i].chinese >> arr[i].math >> arr[i].english;
		arr[i].id = i + 1;
		arr[i].S1();
	}
	sort(arr + 1,arr + 1 + n, cmp);
	for(int i = 0;i < 5;i++)
	{
		cout << arr[i].id <<" "<<arr[i].total<<endl;
		
		
		
	}
	return 0;
}
